import fetch from 'assets/js/fetch'
import { AJAX_SERVICE_HOST } from 'api/config'

export function getApiUrl(url) {
  return AJAX_SERVICE_HOST + url
}

/**
 * 个人信息
 */
// export function getUserBaseInfo() {
//   const url = getApiUrl('account/basic')
//   return fetch.get(url)
// }

/**
 * 修改用户信息
 * @param {any} params
 */
export function submitUserBaseInfo(params) {
  const url = getApiUrl('user/basic')
  return fetch.post(url, params)
}

/**
 * 删除历史记录
 * @export
 * @param {*} params
 */
export function deleteHistory(id, type) {
  const url = getApiUrl('user/history/delete')
  return fetch.post(url, {
    resId: id,
    resType: type
  })
}

/**
 * 删除个人收藏
 * @export
 * @param {*} params
 */
export function deleteFavorite(params) {
  const url = getApiUrl('account/favorite/delete')
  return fetch.post(url, params)
}

/**
 * 修改用户信息
 * @param {any} params
 */
export function updateUserInfo(params) {
  const url = getApiUrl('user/basic')
  params = Object.assign({
    'nickName': null,
    'gender': null,
    'areaId': null,
    'branchId': null,
    'score': null,
    'phone': null
  }, params)
  return fetch.post(url, params)
}

/**
 * 获得用户首页信息
 */
export function getUserBaseInfo() {
  const url = getApiUrl('user/index')
  return fetch.get(url)
}

/**
 * 获得用户信息
 */
export function getUserInfo() {
  const url = getApiUrl('user/basic')
  return fetch.get(url)
}

/**
 * 取消关注学校
 */
export function unlikeCollege(params) {
  const url = getApiUrl('index/college/unlike')
  return fetch.post(url, params)
}

/**
 * 院校对比
 * @param {collegeIds} params
 */
export function compareCollege(params) {
  const url = getApiUrl('user/compare/college')
  return fetch.post(url, params)
}